﻿using System;
using System.Linq;
using AutoStopApp.Core;
using AutoStopData.Domains;
using AutoStopData.Model;

namespace AutoStopApp
{
    public partial class Default : AjaxPage
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            var url = WsaaManager.Data.First( ai => ai.Resource == WsaaManager.WsaaResource.DefaultInnerPage && ai.UserTypeName == GetUserTypeName(SessionProvider.CurrentSession)).MenuItem.Url;
            Response.Redirect(url);
        }

        private static UserTypes.Name GetUserTypeName(Session session)
        {
            var retVal = UserTypes.Name.None;
            if (session != null)
            {
                retVal = UserTypes.GetName(session.User.UserTypeCode);
            }
            return retVal;
        }
    }
}